package cn.cheln.explorer.ds.database.copersynch;

import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import cn.cheln.explorer.beans.FileInfo;
import cn.cheln.explorer.ds.MediaArgs;
import cn.cheln.explorer.ds.database.MimeSrc;
import cn.cheln.explorer.ds.util.ContentValuesUtil;
import cn.cheln.support.images.FileTypeInfo;
import cn.cheln.support.log.Logs;
import com.direction.hold.ui.CommonActivity;
import java.io.File;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DatasrcRename
{
  static Thread renamethread = null;

  public static void delete(Context paramContext, Uri paramUri, String paramString)
  {
    paramContext.getContentResolver().delete(paramUri, "_data like ?", new String[] { paramString });
  }

  public static void invokeUpdate(FileInfo paramFileInfo1, FileInfo paramFileInfo2, CommonActivity paramCommonActivity, boolean paramBoolean)
  {
    if (paramFileInfo1.getIsDir().booleanValue())
    {
      renameBatchUpdate(paramFileInfo1, paramFileInfo2, paramCommonActivity);
      return;
    }
    renameSingle(paramFileInfo1, paramFileInfo2, paramCommonActivity, false);
  }

  public static void locate(FileInfo paramFileInfo, CommonActivity paramCommonActivity)
  {
    new Thread(new Runnable(paramCommonActivity, paramFileInfo)
    {
      public void run()
      {
        try
        {
          Thread.sleep(50L);
          Message localMessage = DatasrcRename.this.handler.obtainMessage(5);
          localMessage.obj = this.val$target;
          DatasrcRename.this.handler.sendMessage(localMessage);
          return;
        }
        catch (InterruptedException localInterruptedException)
        {
          Logger.getLogger(DatasrcRename.class.getName()).log(Level.SEVERE, null, localInterruptedException);
        }
      }
    }).start();
  }

  public static void renameBatchUpdate(FileInfo paramFileInfo1, FileInfo paramFileInfo2, CommonActivity paramCommonActivity)
  {
    File[] arrayOfFile;
    if (paramFileInfo1.getIsDir().booleanValue())
    {
      arrayOfFile = paramFileInfo1.getFile().listFiles();
      if (arrayOfFile != null)
        break label28;
      locate(paramFileInfo1, paramCommonActivity);
    }
    return;
    if (paramCommonActivity.renameWaitDialog.isShowing())
    {
      label28: int i = arrayOfFile.length;
      for (int j = 0; ; ++j)
      {
        if (j >= i)
        {
          renameSingle(paramFileInfo1, paramFileInfo2, paramCommonActivity, true);
          return;
        }
        File localFile = arrayOfFile[j];
        renameRecursive(new FileInfo(localFile, paramCommonActivity), new FileInfo(paramFileInfo2.getPath() + "/" + localFile.getName()), paramCommonActivity, true);
      }
    }
    paramCommonActivity.renameWaitDialog.show();
    new Thread(arrayOfFile, paramCommonActivity, paramFileInfo2, paramFileInfo1)
    {
      public void run()
      {
        super.run();
        File[] arrayOfFile = DatasrcRename.this;
        int i = arrayOfFile.length;
        for (int j = 0; ; ++j)
        {
          if (j >= i)
          {
            DatasrcRename.renameSingle(this.val$target, this.val$src, this.val$commonActivity, true);
            Message localMessage = new Message();
            localMessage.obj = this.val$target;
            localMessage.what = 18;
            this.val$commonActivity.handler.sendMessage(localMessage);
            return;
          }
          File localFile = arrayOfFile[j];
          DatasrcRename.renameRecursive(new FileInfo(localFile, this.val$commonActivity), new FileInfo(this.val$src.getPath() + "/" + localFile.getName()), this.val$commonActivity, true);
        }
      }
    }
    .start();
  }

  public static void renameRecursive(FileInfo paramFileInfo1, FileInfo paramFileInfo2, CommonActivity paramCommonActivity, boolean paramBoolean)
  {
    int i = 0;
    if (paramFileInfo1.getIsDir().booleanValue())
    {
      File[] arrayOfFile = paramFileInfo1.getFile().listFiles();
      if (arrayOfFile == null)
      {
        if (!(paramBoolean))
          locate(paramFileInfo1, paramCommonActivity);
        return;
      }
      int j = arrayOfFile.length;
      while (true)
      {
        if (i >= j)
        {
          renameSingle(paramFileInfo1, paramFileInfo2, paramCommonActivity, true);
          return;
        }
        File localFile = arrayOfFile[i];
        renameRecursive(new FileInfo(localFile, paramCommonActivity), new FileInfo(paramFileInfo2.getPath() + "/" + localFile.getName()), paramCommonActivity, localFile.isDirectory());
        ++i;
      }
    }
    renameSingle(paramFileInfo1, paramFileInfo2, paramCommonActivity, false);
  }

  public static void renameSingle(FileInfo paramFileInfo1, FileInfo paramFileInfo2, CommonActivity paramCommonActivity, boolean paramBoolean)
  {
    FileTypeInfo localFileTypeInfo1 = FileTypeInfo.getTypeInfo(paramFileInfo1);
    if (paramBoolean)
    {
      Uri localUri2 = MediaArgs.dirUri;
      ContentValues localContentValues3 = ContentValuesUtil.constructContentValues(paramFileInfo1, localFileTypeInfo1);
      ContentResolver localContentResolver2 = paramCommonActivity.getContentResolver();
      String[] arrayOfString2 = new String[1];
      arrayOfString2[0] = paramFileInfo2.getPath();
      localContentResolver2.update(localUri2, localContentValues3, "_data like ?", arrayOfString2);
    }
    do
    {
      return;
      paramFileInfo1.buildName();
      paramFileInfo2.buildName();
      FileTypeInfo localFileTypeInfo2 = FileTypeInfo.getTypeInfo(paramFileInfo2);
      if (localFileTypeInfo2.ext.equalsIgnoreCase(localFileTypeInfo1.ext))
      {
        Uri localUri1 = localFileTypeInfo1.uri;
        if (localFileTypeInfo1.uri != null)
        {
          ContentValues localContentValues2 = ContentValuesUtil.constructContentValues(paramFileInfo1, localFileTypeInfo1);
          ContentResolver localContentResolver1 = paramCommonActivity.getContentResolver();
          String[] arrayOfString1 = new String[1];
          arrayOfString1[0] = paramFileInfo2.getPath();
          localContentResolver1.update(localUri1, localContentValues2, "_data like ?", arrayOfString1);
        }
        while (true)
        {
          Message localMessage = new Message();
          localMessage.what = 5;
          paramCommonActivity.handler.sendMessage(localMessage);
          return;
        }
      }
      if (!(MimeSrc.categoryRepository.containsKey(localFileTypeInfo2.category)))
        continue;
      Logs.i("", "mimePrefix -------------> remove " + localFileTypeInfo2.mime + " " + localFileTypeInfo2.category);
      DatasrcDelete.recursiveUpdateDel(paramFileInfo2, paramCommonActivity);
    }
    while (!(MimeSrc.categoryRepository.containsKey(localFileTypeInfo1.category)));
    Logs.i("", "mimePrefix -------------> add " + localFileTypeInfo1.mime + " " + localFileTypeInfo1.uri + " " + localFileTypeInfo1.category);
    ContentValues localContentValues1 = ContentValuesUtil.constructContentValues(paramFileInfo1, localFileTypeInfo1);
    paramCommonActivity.getContentResolver().insert(localFileTypeInfo1.uri, localContentValues1);
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.explorer.ds.database.copersynch.DatasrcRename
 * JD-Core Version:    0.5.2
 */